package com.mdxl.layer_cj.service;


import com.mdxl.layer_cj.manager.MybatisManager;
import com.mdxl.layer_cj.mapper.UserMapper;
import com.mdxl.layer_cj.shiro.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service("mybatisService")
public class MybatisService{

    /*
    * 这里会出现 userMapper 红色下划线，是因为配置原因
    * IDEA在编辑时提示could not autowire
    * 解决办法 File-Project Structure 页面 Facets下删掉 Spring(直接右键Delete）
    * */
    @Resource
    UserMapper userMapper;

    @Resource(name = "mybatisManager")
    MybatisManager mybatisManager;

    public void add(User user){
       mybatisManager.add(user);
    }

    public User getUser(String id){
        return userMapper.getUser(id);
    }

    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.MANDATORY,readOnly = true)
    public void addUser(User user){
        userMapper.addUser(user);
    }
    public void delUser(String id){
        userMapper.delUser(id);
    }
    public void updateUser(User user){
        updateUser(user);
    }

}
